"""
Case Type   : float精度扩展
Case Name   : gs_guc设置float_as_numeric
Create At   : 2024/9/25
Owner       : @kyleze
Description :
    1.gs_guc reload设置参数gs_guc设置float_as_numeric
Expect      :
    1.成功
    2.成功
History     :
"""

import os
import unittest

from testcase.utils.Logger import Logger
from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant


class FloatAndNumericTestCase(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info(f'----{os.path.basename(__file__)} start----')
        self.primary_sh = CommonSH('PrimaryDbUser')
        self.constant = Constant()
        self.common = Common('PrimaryDbUser')
        self.behavior_compat_options_default = self.common.show_param(
            'behavior_compat_options')

    def test_float_numerict(self):
        step = '--step1:gs_guc reload设置参数gs_guc设置float_as_numeric ' \
               'expect:成功--'
        self.log.info(step)
        load_result = self.primary_sh.execute_gsguc(
            'reload', self.constant.GSGUC_SUCCESS_MSG,
            "behavior_compat_options = 'float_as_numeric'")
        self.log.info(load_result)
        self.assertTrue(load_result, '执行失败' + step)
        show_res = self.common.show_param('behavior_compat_options')
        self.assertIn('float_as_numeric', show_res, '执行失败' + step)

    def tearDown(self):
        self.log.info('--清理环境')
        load_result = self.primary_sh.execute_gsguc(
            'reload', self.constant.GSGUC_SUCCESS_MSG,
            f"behavior_compat_options = "
            f"'{self.behavior_compat_options_default}'")
        self.log.info(load_result)
        self.assertTrue(load_result, '参数设置失败')
        self.log.info(f'----{os.path.basename(__file__)} end----')

